[URL, CAPTCHA] = require('../config/captcha')
axios = require('axios')

module.exports = {}

_new = (id_secret)->
    (ctx)->
        {ticket, appid, randstr} = ctx.request.body
        {data} = await axios.get(
            URL
            params:{
                aid:appid
                AppSecretKey:id_secret[appid]
                Ticket:ticket
                Randstr:randstr
                UserIP:ctx.ip
            }
        )
        if 1!=(data.response-0)# or 1
            raise captcha:1

do ->
    for k,v of CAPTCHA
        module.exports[k] = _new(v)
